﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_BLL;
using QLTV_Public;

namespace QLTV_GiaoDien
{
    public partial class uc_ViPham : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_ViPham()
        {
            InitializeComponent();
        }
        ViPham_BLL viPham_bll = new ViPham_BLL();
        public void GetData(int kt)
        {
            txt_Load.Text = kt.ToString();
        }
        private void uc_ViPham_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = viPham_bll.LayDuLieu();
            txt_Load.Hide();
        }
        private void bbi_Them_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_ViPham f = new frm_ViPham();
            f.Flag = 0;
            f.MyGetData = new frm_ViPham.GetInt(GetData);
            f.ShowDialog();
        }

        private void bbi_Sua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_ViPham f = new frm_ViPham();
            f.Flag = 1;
            f.MyGetData = new frm_ViPham.GetInt(GetData);
            f.MaViPham = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Vi Phạm").ToString());
            f.MaDocGia = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Độc Giả").ToString());
            f.LyDoViPham = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Lý Do Vi Phạm").ToString();
            f.HinhThuc = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Hình Thức").ToString();
            f.NgayXuLy = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ngày Xử Lý").ToString();
            f.NguoiXuLy = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Nhân Viên Xử Lý").ToString();
            f.ShowDialog();
        }

        private void bbi_Xem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_ViPham f = new frm_ViPham();
            f.Flag = 2;
            f.MyGetData = new frm_ViPham.GetInt(GetData);
            f.MaViPham = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Vi Phạm").ToString());
            f.MaDocGia = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Độc Giả").ToString());
            f.LyDoViPham = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Lý Do Vi Phạm").ToString();
            f.HinhThuc = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Hình Thức").ToString();
            f.NgayXuLy = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ngày Xử Lý").ToString();
            f.NguoiXuLy = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Nhân Viên Xử Lý").ToString();
            f.ShowDialog();
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            frm_ViPham f = new frm_ViPham();
            f.Flag = 2;
            f.MyGetData = new frm_ViPham.GetInt(GetData);
            f.MaViPham = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Vi Phạm").ToString());
            f.MaDocGia = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Độc Giả").ToString());
            f.LyDoViPham = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Lý Do Vi Phạm").ToString();
            f.HinhThuc = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Hình Thức").ToString();
            f.NgayXuLy = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ngày Xử Lý").ToString();
            f.NguoiXuLy = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Nhân Viên Xử Lý").ToString();
            f.ShowDialog();
        }

        private void bbi_Xoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ViPham_Public vp = new ViPham_Public();
            vp.MaViPham=Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Mã Vi Phạm").ToString());
            vp.TenDocGia =gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Họ Và Tên").ToString();
            if (XtraMessageBox.Show("Bạn có muốn xóa Mã vi phạm: '" + vp.MaViPham + "' của Độc giả: '" + vp.TenDocGia + "' này không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                viPham_bll.Delete_ViPham(vp);
                uc_ViPham_Load(sender,e);
            }
        }

        private void bbi_Refresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            uc_ViPham_Load(sender,e);
        }

        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                uc_ViPham_Load(sender,e);
                txt_Load.Text = "0";
            }
        }


    }
}
